Getting your computer ready so you can learn!
Welcome! There’s a few things we’d like everyone to try and do before the workshop starts. For this workshop and the following lessons, we need to install the following programs/software in this order (more details below for different operating systems):
Install R Packages & Test They Work
Install Geospatial Packages and
Download Data for the Workshop
Below, we provide extra details appropriate for Windows and MacOSX operating systems. For additional installation options, see here.
R is the underlying statistical computing environment, or the engine we use to do things.
Go to CRAN and download the R installer for Windows. Make sure to choose the latest stable version (v4.1.0 as of May 2021). Download the .exe file and double click to install.
C:\Program Files\R (version number may vary), and you may need administrative privileges to do this if you’re not working on your personal computer.At the “Select Components” screen, you can accept the default and install both 32-bit and 64-bit versions.
At this screen, uncheck “Create a desktop icon” because non-admin users in Windows will be unable to delete it.
.pkg file for the latest R versionUsing R alone is possible, but less ideal (and less fun!). RStudio is an open-source graphical Integrated Development Environment or IDE that makes using R much easier and more interactive. In this course, we will use the free RStudio Desktop version.
Once installed, RStudio should be accessible from the start menu. Start up RStudio.
Copy and paste the following code: Once in that console window, copy the code below and paste it into the Console window (just to the right of the little >). Then hit ENTER.
version$version.stringVerify your installed R version is v4.1.0: Ideally you should be running the latest stable release (v4.1.0 as of May 2021). If you have an older version, please install the newest version using the instructions above.
Here is what a current R version looks like.
[1] "R version 4.1.0 (2021-05-18)"
The core set of packages we will need are as follows. There may be a few more we need to install during the course, but this should be the majority.
We install packages available for all R users from an online repository called CRAN, by pasting the following code into the RStudio Console window and hitting ENTER.
install.packages("tidyverse")
install.packages("viridis")
install.packages("openxlsx")
install.packages("readxl")
install.packages("lubridate")
You may see a message
There are binary versions available but the source versions are later:followed by a list of the packages you are trying to install. This is usually followed by this message:
Do you want to install from sources the package which needs compilation? (Yes/no/cancel)Compilation means the code associated with the package needs to be translated into R and built for your operating system. Generally we can use the binary option, so after that message type “No” and hit “Enter” on the keyboard. In some cases we do need/want to compile the package to get the most recent updates. For this course, try installing from binary (type No) first!
You may see this:
That’s OK! There’s a dialog box hiding behind RStudio asking if you want to create a personal folder in your Documents folder. Click Yes. It will look something like this when done:
For some of the mapping and spatial lessons, we need a set of geospatial tools/packages. For the majority of the content we will cover, this requires installation of the {sf} package. If installing from a binary package, this should work (just make sure to type “No” when asked about install from sources):
install.packages("sf")
install.packages("mapview")
However, more commonly, we may need to install/update from source to have the most updated functions and options from a package (don’t worry if you have no idea what this all means yet!). To do so, we need to follow instructions below for the operating system of your choice.
To install {sf} successfully from source, Windows users will need to install Rtools. Download the 64-bit compiler, and follow the instructions to add the PATH. This requires administrative privileges.
For MacOS users, follow the recommended instructions on the {sf} webpage, which if possible, requires opening a Terminal window and successfully installing Homebrew with the code at this website. You can test if brew is installed by typing brew config in the Terminal and hitting Enter.
We can then install a few spatial tools (via Terminal still!) with the following code:
brew install pkg-config
# then hit enter and wait
brew install gdal
# then hit enter and wait
At this point, you should now be able to install {sf} from binary on a Mac. Proceed to the next section!
After this has successfully installed, return to the RStudio “Console”, and install the following packages by typing the following into the console and pressing “return” on the keyboard:
install.packages("sf")
install.packages("mapview")
For {sf}, try installing from binary first (so type “No” in your R Console window and hit Enter).
Success should return something like this (not an error message) when you load the library with library(sf):
library(sf)
# Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1We’ll be working with a few different datasets for this workshop (see here). We’ve zipped all these files into a single folder, which can be downloaded here. Bear in mind this .zip file is ~122 MB in size, and may take a few minutes to download depending on internet connections.
Just to make sure each package installed successfully, do the following:
>)# check that these packages are installed successfully:
c("tidyverse", "sf", "viridis", "mapview") %in% installed.packages()
[1] TRUE TRUE TRUE TRUE
If you have successfully installed packages, you should see a list of “TRUE” repeated once for each package listed inside the c( ).
Previous module:
Introduction Next module:
2. Getting started
If you see mistakes or want to suggest changes, please create an issue on the source repository.
Text and figures are licensed under Creative Commons Attribution CC BY 4.0. Source code is available at https://github.com/r4wrds/r4wrds, unless otherwise noted. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".